<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="com.cgt.web.pojo.Banji" %>
<%@ page import="com.cgt.web.util.PageInfo" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Banji</title>
    <link rel="stylesheet" href="static/bootstrap-3.4.1-dist/css/bootstrap.css">
</head>
<body>
    <%
//      List<Banji> list = (List<Banji>) request.getAttribute("list");
        PageInfo<Banji> pageInfo = (PageInfo<Banji>) request.getAttribute("pageInfo");
    %>
    <a class="btn btn-success" href="banji_add.jsp">添加</a>
    <table class="table table-striped table-bordered table-hover table-condensed">
      <tr>
        <td>ID</td>
        <td>姓名</td>
        <td>地址</td>
      </tr>
      <c:forEach items="${pageInfo.list}" var="banji">
          <tr>
              <td>${banji.id}</td>
              <td>${banji.name}</td>
              <td>${banji.address}</td>
              <td><a href="/banji?method=toUpdate&id=${banji.id}">修改</a></td>
              <td><a href="javascript:void(0)" onclick="deleteById(${banji.id})">删除</a></td>
          </tr>
      </c:forEach>
    </table>
<%--      <%--%>
<%--        for (Banji banji : pageInfo.getList()) {--%>
<%--      %>--%>
<%--      <tr>--%>
<%--        <td><%=banji.getId()%></td>--%>
<%--        <td><%=banji.getName()%></td>--%>
<%--        <td><%=banji.getAddress()%></td>--%>
<%--        <td><a href="/banji?method=toUpdate&id=<%=banji.getId()%>">修改</a></td>--%>
<%--        <td><a href="javascript:void(0)" onclick="deleteById(<%=banji.getId()%>)">删除</a></td>--%>
<%--      </tr>--%>
<%--      <%--%>
<%--        }--%>
<%--      %>--%>

    <nav aria-label="Page navigation">
        <ul class="pagination">
            <c:if test="${pageInfo.pageNo==1}">
                <li class="disabled">
                    <a href="#" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=1}">
                <li>
                    <a href="/banji?method=selectByPage&pageNo=${pageInfo.pageNo-1}" aria-label="Previous">
                        <span aria-hidden="true">&laquo;</span>
                    </a>
                </li>
            </c:if>

            <c:forEach begin="1" end="${pageInfo.totalPage}" step="1" var="i">
                <c:if test="${i==pageInfo.pageNo}">
                    <li class="active"><a href="#">${i}</a></li>
                </c:if>
                <c:if test="${i!=pageInfo.pageNo}">
                    <li><a href="/banji?method=selectByPage&pageNo=${i}&pageSize=5">${i}</a></li>
                </c:if>
            </c:forEach>
<%--            <%--%>
<%--                for (int i = 1; i <= pageInfo.getTotalPage() ; i++) {--%>
<%--                    if(i == pageInfo.getPageNo()){--%>
<%--            %>--%>
<%--                        <li class="active"><a href="#"><%=i%></a></li>--%>
<%--            <%--%>
<%--                    } else{--%>
<%--            %>--%>
<%--                        <li><a href="/banji?method=selectByPage&pageNo=<%=i%>&pageSize=5"><%=i%></a></li>--%>
<%--            <%--%>
<%--                    }--%>
<%--                }--%>
<%--            %>--%>

            <c:if test="${pageInfo.pageNo==pageInfo.totalPage}">
                <li class="disabled">
                    <a href="#" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
            <c:if test="${pageInfo.pageNo!=pageInfo.totalPage}">
                <li>
                    <a href="/banji?method=selectByPage&pageNo=${pageInfo.pageNo+1}" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                    </a>
                </li>
            </c:if>
        </ul>
    </nav>
    <script>
      function deleteById(id){
        var isDelete = confirm('真的要删除这条记录吗？');
        if(isDelete){
          location.href = "/banji?method=deleteById&id=" + id;
        }
      }
    </script>
</body>
</html>
